@push('title')
    <title>携程比价</title>
@endpush
@push('style2')

@extends('layout.layer')
@section('content')

<form class="layui-form ctrip-form-box"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
        <div class="layui-form-item">

            @if((in_array(10,request()->admin_platform) && in_array(11,request()->admin_platform)) || in_array(20,request()->admin_platform) && in_array(21,request()->admin_platform))

                <div class="layui-form-item">
                    <label class="layui-form-label">所上平台</label>
                    <div class="layui-input-inline">
                        <select name="platform">
                            <option value="10">恒博携程</option>
                            <option value="11">茂华携程</option>
                        </select>
                    </div>
                </div>
            @elseif(in_array(10,request()->admin_platform) || in_array(20,request()->admin_platform))
                <input type="hidden" name="platform" value="10">
            @elseif(in_array(11,request()->admin_platform) || in_array(21,request()->admin_platform))
                <input type="hidden" name="platform" value="10">
            @endif

            <div class="layui-inline">
                <label class="layui-form-label">航程类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="type" value="0" title="单程" checked>
                    <input type="radio" name="type" value="1" title="往返">
                    <input type="radio" name="type" value="2" title="中转联程">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">机场/城市</label>
                <div class="layui-input-block">
                    <input type="radio" name="airport" value="0" title="机场代码" checked>
                    <input type="radio" name="cityCode" value="1" title="城市代码">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">机场代码</label>
            <div class="layui-input-block" style="display: flex; justify-content: flex-start; align-items: center;">
                <input type="text" name="DepartPort" value="" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input"
                    style="width:200px;">
                <span style="padding: 0 10px;">到</span>
                <input type="text" name="ArrivePort" value="" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input"
                    style="width:200px;">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">政策类型</label>
                <div class="layui-input-block">
                    <select name="TradePolicyType" lay-filter="aihao">
                        <option value="ALL">所有</option>
                        <option value="RAWPOLICY">普通政策</option>
                        <option value="SPECIALPOLICY">特殊政策</option>
                        <option value="RULEPOLICY">特殊政策</option>
                        <option value="NDC">单程NDC</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">航班号</label>
                <div class="layui-input-block">
                    <input type="text" name="FlightNumber" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item" style="width: 544px;">
            <label class="layui-form-label">产品类型</label>
            <div class="layui-input-block">

                <div id="ShareProductTypeList"></div>

            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">航班日期</label>
            <div class="layui-input-block" style="display: flex; justify-content: flex-start; align-items: center;">
                <input type="text" name="EffectDate" placeholder="政策旅行日期" value="" lay-verify="required" class="layui-input" id="laydate1" style="width:200px;">
                <span style="padding: 0 10px;">-</span>
                <input type="text" name="ExipryDate" placeholder="请选择" value="" lay-verify="required" class="layui-input" id="laydate2" style="width:200px;">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">航空公司</label>
                <div class="layui-input-block">
                    <input type="text" name="AirLine" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">舱位代码</label>
                <div class="layui-input-block">
                    <input type="text" name="GoSubClass" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">共享航班</label>
                <div class="layui-input-block">
                    <input type="radio" name="IsShareFlight" value="A" title="不限" checked>
                    <input type="radio" name="IsShareFlight" value="T" title="是">
                    <input type="radio" name="IsShareFlight" value="F" title="否">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">渠道</label>
                <div class="layui-input-block">
                    <select name="SaleChannel" lay-filter="aihao">
                        <option value="FlightOnline">FlightOnline</option>
                        <option value="Mobile" selected>Mobile</option>
                        <option value="MobileH5">MobileH5</option>
                        <option value="Vacation">Vacation</option>
                        <option value="AirHotelPackage">AirHotelPackage</option>
                        <option value="ZhiXing">ZhiXing</option>
                    </select>
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">查询</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <form class="layui-form" style="background-color: #ffffff;border-left:1px solid #eee;border-top:1px solid #eee;border-right:1px solid #eee;margin-top:10px;">
        <div class="layui-form-item" style="margin-bottom:0;padding: 10px 0;">
            <label class="layui-form-label">共3条记录</label>
            <div style="display: flex;justify-content: flex-start;align-items:center;">
                <div class="layui-input-block" style="margin-left: 0;">
                    <input type="checkbox" name="like[write]" title="全选所有" checked>
                    <input type="checkbox" name="like[read]" title="选择未投放政策">
                    <input type="checkbox" name="like[dai]" title="选择无优势政策">
                </div>
                <div>
                    <button class="layui-btn layui-btn-sm" lay-submit lay-filter="formDemo">调价</button>
                    <button class="layui-btn layui-btn-sm" lay-submit lay-filter="formDemo">导出</button>
                </div>
            </div>
        </div>
    </form>
    <table id="list" lay-filter="list"></table>
@endsection
@push('script')
    <script src="/static/xml-select/xm-select.js"></script>
    <script>
        
        layui.use(['table', 'form', 'laydate'], function () {
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;

            var source_type = xmSelect.render({
                el: '#ShareProductTypeList',
                language: 'zn',
                name: 'ShareProductTypeList',
                theme: {
                    color: '#666', // 设置主题颜色
                },
                data: [
                    {name: '商务优选', value: "BusinessPriority",selected:true},
                    {name: '旅行套餐', value: 'TravelPackage',selected:true},
                    {name: '优选套餐', value: 'PriorityPackage',selected:true},
                    {name: '限制类产品', value: "Limited",selected:true}
                ]
            });

        //执行一个laydate实例
        laydate.render({
            elem: '#laydate1' //指定元素
        });
        laydate.render({
            elem: '#laydate2' //指定元素
        });

        //日期转发
        var dateSwitch = function (timestamp) {

            console.log(timestamp);
            var date = new Date(timestamp);
            var year = date.getFullYear();
            var month = ("0" + (date.getMonth() + 1)).slice(-2);
            var day = ("0" + date.getDate()).slice(-2);
            var formattedDate = year + "-" + month + "-" + day;
            console.log(formattedDate);
            return formattedDate;
        }

        //第一个实例
        table.render({
            id: 'list'
            , elem: '#list'
            , url: '/compare/ajaxCtrip'
            , page: false //开启分页
            ,limit: 10000
            ,parseData: function (res) { //将原始数据解析成 table 组件所规定的数据

                if(res.errcode != null && res.errcode != 0){ // 判断数据是否为空

                    layer.msg(res.errmsg, {
                        offset: '15px'
                        ,icon: 5
                        ,time: 2000
                    });
                }

                return {
                    "code": res.errcode, //解析接口状态
                    "msg": res.errmsg, //解析提示文本
                    "data":res.data,
                    "count": res.data.length, //解析数据长度
                };
            }
            , cols: [[ //表头
                { type: 'checkbox', fixed: 'left' }
                , {type: 'numbers',title: '序号', width: 80, sort: true, fixed: 'left'}
                , { field: 'PolicyID', title: '政策ID' }
                , { field: 'DepartDate', title: '航班日期', sort: true, templet: function (row) {
                        return dateSwitch(parseInt(row.DepartDate.substring(6,19)));
                    } }
                , { field: 'DepartPort', title: '航线' ,templet: function (row) {
                        return row.DepartPort +'-'+row.DepartPort
                    }}
                , { field: 'Flight', title: '航班' }
                , { field: 'GoSubClass', title: '舱位' }
                , { field: 'ShareProductType', title: '产品类型', sort: true,templet: function (row) {
                        switch (row.ShareProductType) {

                            case 'BusinessPriority':        return '商务优选';
                            case 'TravelPackage':           return '旅行套餐';
                            case 'PriorityPackage':         return '优选套餐';
                            case 'LimitedCardType':         return '证件限制';
                            case 'LimitedIndentityCard':    return '身份证前四位限制';
                            case 'LimitedAge':              return '年龄限制';
                            case 'LimitedPassengerNum':     return '人数限制';
                            case 'GreatValue':              return '';
                            case 'SurpriseAirLine':         return '';
                            case 'DiscountBusiness':        return '';
                            case 'BusinessPreference':      return '';
                        }
                    } }
                , { field: 'TradePolicyType', title: '政策类型',templet: function (row) {
                        switch (row.TradePolicyType) {

                            case 'SPECIALPOLICY': return '特殊政策';
                            case 'RULEPOLICY': return '规则运价';
                            case 'RAWPOLICY': return '普通政策';
                            case 'NA': return '其他';
                            case 'NDC': return '单程NDC';
                        }
                    } }
                , { field: 'CostPrice', title: '原始底价', sort: true }
                , { field: 'PKCostPrice', title: '指导价', sort: true }
                , { field: 'PrintPrice', title: '票页价', sort: true }
                , { field: 'NoResultReason', title: '指导价不输出原因', sort: true }
                , { field: 'IsOwnPolicy', title: '我的政策', sort: true,templet: function (row) {

                   if(row.IsOwnPolicy == 'F'){

                       return '<span style="width:50px;height:25px;border-radius:25px;display:block;background:#bbb"></span>'
                   }

                   if(row.IsOwnPolicy == 'T') {

                       if(row.CanDisplay) {

                           return '<span style="width:50px;height:25px;border-radius:25px;display:block;background:#34C758"></span>'
                       }

                       return '<span style="width:50px;height:25px;border-radius:25px;display:block;background:#1890ff"></span>'
                   }


                    } }
                /*, { field: 'wealth5', title: '操作', sort: true }*/
            ]]
        });

            //监听提交
            form.on('submit(formDemo)', function(data){

                table.reload('list',{
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where:data.field
                });

                return false;
            });

        // 监听表格复选框选择
        table.on('checkbox(list)', function (obj) {
            var checkStatus = table.checkStatus('demo'); // 获取表格的选中状态
            console.log(checkStatus.data); // 打印选中的数据
            console.log(obj.checked); // 当前是否选中
            console.log(obj.data); // 当前行的数据
        });

    });
        
    </script>
    <style>
        .ctrip-form-box .layui-inline {
            width: 544px;
        }
    </style>
@endpush
